# frozen_string_literal: true

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_hotel
    # identified_by :current_user

    def connect
      # byebug
      # self.current_user = find_verified_user
      self.current_hotel = find_verified_hotel
    end

    protected

    # def find_verified_user
    #   user = User.find_by(id: request.params[:user_id]) || User.find_by(id: cookies.signed[:user_id])
    #   user || reject_unauthorized_connection
    #   # User.find(cookies.signed[:user_id]) || reject_unauthorized_connection
    # end

    def find_verified_hotel
      hotel = Hotel.find_by(id: request.params[:hotel_id])
      hotel || reject_unauthorized_connection
      # User.find(cookies.signed[:user_id]) || reject_unauthorized_connection
    end
  end
end
